


import op_route 
import keti4_config as config
import time
import sys

# from op.op_route import RouterClient, DATA_TYPE_SEND, DATA_TYPE_GET_NEIGHBORS,DATA_TYPE_NEIGHBORS


TARGET_NODE = 0x02


def read_data(file_path):
    with open(file_path, "rb") as f:
        data = f.read()
    return data

def send_data( data,  target_node = TARGET_NODE, recv_port = 8800):
    # 初始化路由器客户端
    router = op_route.RouterClient(host='localhost', port=recv_port)
    router.connect()

    data_bytes = bytes(data)

    # 发送数据
    router.send_packet(op_route.DATA_TYPE_SEND, target_node, len(data_bytes), data_bytes)
    print("Sent data:", data)


if __name__ == "__main__":

    # 获取命令行参数
    # script_name = sys.argv[0]  # 脚本名
    # arguments = sys.argv[1:]   # 除脚本名外的参数列表

    # data = read_data(sys.argv[1])   # 除脚本名外的参数列表
    # target_node = sys.argv[2]  # 脚本名

    data = read_data("data.png")   # 除脚本名外的参数列表
    target_node = 0x02  # 目标节点名称

    send_data(data, target_node, config.recv_port )

    while(True):
        time.sleep(1)

